/*
 * Copyright (c) 2016-2020, Chengdu RST technology co., ltd
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-12-15     shijiabao       the first version
 */
#include <COMMON_HEADER/common_header.h>

#define DBG_TAG "CONFIG"
#define DBG_LVL DBG_LOG

#define DTU_CONFIG_FILE "file"
#define DTU_CONFIG_FILE_PATH "/config"
#define DTU_CONFIG_FILE_NAME "dn400.conf"

#define HARDWARE_VERISON "1.0.0"
#define APP_VERISON "1.0.0"
#define SERIAL_NUMBER "123456789"
#define DTU_NUMBER "123456789"
#define APN_NAME_DEFAULT "cmcc"
#define APN_USER_DEFAULT "0"
#define APN_PASSWORD_DEFAULT "0"

//初始化定义DTU参数
struct device_parm dn400_parm = {{{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}},{{0},{0},0,0,0,0,0,0,0,0,0,0,0,0,0},{NULL},{NULL},{NULL}};

/**
  * @brief  写入dn400默认参数配置
  * @param  无
  * @retval 无
  */
static void write_defalut_parm(void)
{
    sprintf(dn400_parm.dn400_configure.product_name,"DN400");
    sprintf(dn400_parm.dn400_configure.hardware_version,HARDWARE_VERISON);
    sprintf(dn400_parm.dn400_configure.soft_version,APP_VERISON);
    sprintf(dn400_parm.dn400_configure.serial_number,SERIAL_NUMBER);
    sprintf(dn400_parm.dn400_configure.dtu_number,DTU_NUMBER);

    sprintf(dn400_parm.dn400_configure.apn_using_flag,"off");
    sprintf(dn400_parm.dn400_configure.apn_name,APN_NAME_DEFAULT);
    sprintf(dn400_parm.dn400_configure.apn_user,APN_USER_DEFAULT);
    sprintf(dn400_parm.dn400_configure.apn_password,APN_PASSWORD_DEFAULT);

    sprintf(dn400_parm.dn400_configure.data_transmission_mode,"1");
    sprintf(dn400_parm.dn400_configure.register_packet,"rst");
    sprintf(dn400_parm.dn400_configure.network_mode,"tcp");
    sprintf(dn400_parm.dn400_configure.breathe_packet,"rst");
    sprintf(dn400_parm.dn400_configure.breathe_time,"10");

    sprintf(dn400_parm.dn400_configure.data_center1_ip,"cdrst.asuscomm.com");
    sprintf(dn400_parm.dn400_configure.data_center2_ip,"cdrst.asuscomm.com");
    sprintf(dn400_parm.dn400_configure.data_center1_port,"4000");
    sprintf(dn400_parm.dn400_configure.data_center2_port,"5000");
    sprintf(dn400_parm.dn400_configure.data_center1_using_flag,"ON");
    sprintf(dn400_parm.dn400_configure.data_center2_using_flag,"ON");
    sprintf(dn400_parm.dn400_configure.private_data_center_ip,"cdrst.asuscomm.com");
    sprintf(dn400_parm.dn400_configure.private_data_center_port,"6000");

    sprintf(dn400_parm.dn400_configure.rs485_baud_rate,"9600");
    sprintf(dn400_parm.dn400_configure.rs485_data_bit,"8");
    sprintf(dn400_parm.dn400_configure.rs485_check_bit,"NONE");
    sprintf(dn400_parm.dn400_configure.rs485_stop_bit,"1");

    sprintf(dn400_parm.dn400_configure.rs232_baud_rate,"9600");
    sprintf(dn400_parm.dn400_configure.rs232_data_bit,"8");
    sprintf(dn400_parm.dn400_configure.rs232_check_bit,"NONE");
    sprintf(dn400_parm.dn400_configure.rs232_stop_bit,"1");

    sprintf(dn400_parm.dn400_configure.private_instruction1,"0");
    sprintf(dn400_parm.dn400_configure.private_instruction2,"0");
    sprintf(dn400_parm.dn400_configure.private_instruction3,"0");
    sprintf(dn400_parm.dn400_configure.private_instruction4,"0");

    sprintf(dn400_parm.dn400_configure.mqtt_using_flag,"off");
    sprintf(dn400_parm.dn400_configure.mqtt_url,"0");
    sprintf(dn400_parm.dn400_configure.mqtt_username,"0");
    sprintf(dn400_parm.dn400_configure.mqtt_password,"0");
    sprintf(dn400_parm.dn400_configure.mqtt_subtopic,"0");
    sprintf(dn400_parm.dn400_configure.mqtt_pubtopic,"0");
    sprintf(dn400_parm.dn400_configure.mqtt_willmsg,"0");
}

/**
  * @brief  写入参数到配置中
  * @param  无
  * @retval 无
  */
void write_parm_to_config(int fd)
{
    char buf[0x100]={0};
    memset(buf,0,sizeof(buf));
    sprintf(buf,"ProductName=%s\n",dn400_parm.dn400_configure.product_name);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"HardwareVersion=%s\n",dn400_parm.dn400_configure.hardware_version);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"SoftVersion=%s\n",dn400_parm.dn400_configure.soft_version);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"SerialNumber=%s\n",dn400_parm.dn400_configure.serial_number);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DtuCode=%s\n",dn400_parm.dn400_configure.dtu_number);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"ApnSwitch=%s\n",dn400_parm.dn400_configure.apn_using_flag);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"ApnName=%s\n",dn400_parm.dn400_configure.apn_name);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"ApnUserName=%s\n",dn400_parm.dn400_configure.apn_user);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"ApnPassword=%s\n",dn400_parm.dn400_configure.apn_password);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataTransmissionMode=%s\n",dn400_parm.dn400_configure.data_transmission_mode);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"RegisterPacket=%s\n",dn400_parm.dn400_configure.register_packet);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"NetworkMode=%s\n",dn400_parm.dn400_configure.network_mode);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"BreathePacket=%s\n",dn400_parm.dn400_configure.breathe_packet);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"BreatheTime=%s\n",dn400_parm.dn400_configure.breathe_time);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataCenterIp1=%s\n",dn400_parm.dn400_configure.data_center1_ip);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataCenterPort1=%s\n",dn400_parm.dn400_configure.data_center1_port);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataCenterIp2=%s\n",dn400_parm.dn400_configure.data_center2_ip);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataCenterPort2=%s\n",dn400_parm.dn400_configure.data_center2_port);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataCenterSwitch1=%s\n",dn400_parm.dn400_configure.data_center1_using_flag);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"DataCenterSwitch2=%s\n",dn400_parm.dn400_configure.data_center2_using_flag);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs485BaudRate=%s\n",dn400_parm.dn400_configure.rs485_baud_rate);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs485DataBit=%s\n",dn400_parm.dn400_configure.rs485_data_bit);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs485StopBit=%s\n",dn400_parm.dn400_configure.rs485_stop_bit);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs485CheckBit=%s\n",dn400_parm.dn400_configure.rs485_check_bit);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs232BuadRate=%s\n",dn400_parm.dn400_configure.rs232_baud_rate);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs232DataBit=%s\n",dn400_parm.dn400_configure.rs232_data_bit);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs232StopBit=%s\n",dn400_parm.dn400_configure.rs232_stop_bit);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"Rs232CheckBit=%s\n",dn400_parm.dn400_configure.rs232_check_bit);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"PrivateInstruction1=%s\n",dn400_parm.dn400_configure.private_instruction1);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"PrivateInstruction2=%s\n",dn400_parm.dn400_configure.private_instruction2);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"PrivateInstruction3=%s\n",dn400_parm.dn400_configure.private_instruction3);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"PrivateInstruction4=%s\n",dn400_parm.dn400_configure.private_instruction4);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttSwitch=%s\n",dn400_parm.dn400_configure.mqtt_using_flag);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttServer=%s\n",dn400_parm.dn400_configure.mqtt_url);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttUsername=%s\n",dn400_parm.dn400_configure.mqtt_username);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttPassword=%s\n",dn400_parm.dn400_configure.mqtt_password);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttSubtopic=%s\n",dn400_parm.dn400_configure.mqtt_subtopic);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttPubtopic=%s\n",dn400_parm.dn400_configure.mqtt_pubtopic);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    memset(buf,0,sizeof(buf));
    sprintf(buf,"MqttWillmsg=%s\n",dn400_parm.dn400_configure.mqtt_willmsg);
    LOG_D("%s", buf);
    write(fd, buf, strlen(buf));

    fsync(fd);
}

/**
  * @brief  读取配置到参数中
  * @param  无
  * @retval 无
  */
void read_config_to_parm(int fd)
{
    char string_buf[100] = {0};
    char char_buf[1] = {0};
    char variable[50] = {0};
    char parm[100] = {0};
    int read_len = 0;
    uint8_t read_over_flag = 0;
    int count = 0;

    while(1)
    {
        while(1)
        {
            read_len = read(fd,char_buf,1);
            if(read_len == 0 || read_len == -1)
            {
                read_over_flag = 1;
                break;
            }
            if(char_buf[0] == '\n')
            {
                break;
            }
            else
            {
                string_buf[count] = char_buf[0];
            }
            count=count+1;
        }
        if(read_over_flag == 1) break;
        count = 0;
        LOG_D("读取设备参数：%s", string_buf);

        memset(variable,0,sizeof(variable));
        memset(parm,0,sizeof(parm));
        sscanf(string_buf,"%[^=]=%s",variable,parm);
        if(strstr(variable,"产品名称") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.product_name[j] = parm[j];
            }
        }
        if(strstr(variable,"硬件版本") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.hardware_version[j] = parm[j];
            }
        }
        if(strstr(variable,"软件版本") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.soft_version[j] = parm[j];
            }
        }
        if(strstr(variable,"序列号值") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.serial_number[j] = parm[j];
            }
        }
        if(strstr(variable,"DTU码") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.dtu_number[j] = parm[j];
            }
        }
        if(strstr(variable,"APN开关") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.apn_using_flag[j] = parm[j];
            }
        }
        if(strstr(variable,"APN名称") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.apn_name[j] = parm[j];
            }
        }
        if(strstr(variable,"APN用户") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.apn_user[j] = parm[j];
            }
        }
        if(strstr(variable,"APN密码") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.apn_password[j] = parm[j];
            }
        }
        if(strstr(variable,"数据传输模式") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.data_transmission_mode[j] = parm[j];
           }
        }
        if(strstr(variable,"注册包文") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.register_packet[j] = parm[j];
           }
        }
        if(strstr(variable,"网络模式") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.network_mode[j] = parm[j];
           }
        }
        if(strstr(variable,"心跳包文") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.breathe_packet[j] = parm[j];
           }
        }
        if(strstr(variable,"心跳间隔") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.breathe_time[j] = parm[j];
           }
        }
        if(strstr(variable,"数据中心1IP") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.data_center1_ip[j] = parm[j];
           }
        }
        if(strstr(variable,"数据中心1端口") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.data_center1_port[j] = parm[j];
           }
        }
        if(strstr(variable,"数据中心2IP") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.data_center2_ip[j] = parm[j];
           }
        }
        if(strstr(variable,"数据中心2端口") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.data_center2_port[j] = parm[j];
           }
        }
        if(strstr(variable,"数据中心1开关") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.data_center1_using_flag[j] = parm[j];
          }
        }
        if(strstr(variable,"数据中心2开关") != NULL)
        {
            for(int j=0;j<sizeof(parm);j++)
            {
                dn400_parm.dn400_configure.data_center2_using_flag[j] = parm[j];
            }
        }
        if(strstr(variable,"RS485串口波特率") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.rs485_baud_rate[j] = parm[j];
           }
        }
        if(strstr(variable,"RS485串口数据位") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.rs485_data_bit[j] = parm[j];
           }
        }
        if(strstr(variable,"RS485串口停止位") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.rs485_stop_bit[j] = parm[j];
           }
        }
        if(strstr(variable,"RS485串口奇偶检验") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.rs485_check_bit[j] = parm[j];
           }
        }
        if(strstr(variable,"RS232串口波特率") != NULL)
        {
           for(int j=0;j<sizeof(parm);j++)
           {
               dn400_parm.dn400_configure.rs232_baud_rate[j] = parm[j];
           }
        }
        if(strstr(variable,"RS232串口数据位") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.rs232_data_bit[j] = parm[j];
          }
        }
        if(strstr(variable,"RS232串口停止位") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.rs232_stop_bit[j] = parm[j];
          }
        }
        if(strstr(variable,"RS232串口奇偶检验") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.rs232_check_bit[j] = parm[j];
          }
        }
        if(strstr(variable,"自定义指令1") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.private_instruction1[j] = parm[j];
          }
        }
        if(strstr(variable,"自定义指令2") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.private_instruction2[j] = parm[j];
          }
        }
        if(strstr(variable,"自定义指令3") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.private_instruction3[j] = parm[j];
          }
        }
        if(strstr(variable,"自定义指令4") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.private_instruction4[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT开关") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_using_flag[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT服务器网址") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_url[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT账户用户名") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_username[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT账户密码") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_password[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT订阅主题") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_subtopic[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT推送主题") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_pubtopic[j] = parm[j];
          }
        }
        if(strstr(variable,"MQTT消息") != NULL)
        {
          for(int j=0;j<sizeof(parm);j++)
          {
              dn400_parm.dn400_configure.mqtt_willmsg[j] = parm[j];
          }
        }
        memset(string_buf,0,100);
    }
    close(fd);
}

/**
  * @brief  config初始化，如果初次启动设备，不存在config文件，则创建config文件，写入默认参数配置；如果存在，那么读出参数配置
  * @param  无
  * @retval 无
  */
void dtu_config_file_init(void)
{
    struct stat file_buf;
    char config_file_path[0x20] = {0};
    int config_file_fd = -1;
    if(access(DTU_CONFIG_FILE_PATH, 0))
    {
        //不存在就建立日志路径
        mkdir(DTU_CONFIG_FILE_PATH,0x777);
        LOG_D("Config directory does not exist,establish config directory.");
    }
    sprintf(config_file_path,"%s/%s",DTU_CONFIG_FILE_PATH,DTU_CONFIG_FILE_NAME);
    //查询config文件是否存在，如果不存在则创建该文件，并且写入默认配置项
    if(stat(config_file_path, &file_buf)<0)
    {
        //查询失败
        LOG_D("Config file does not exist,establish config file,wirte parameter.");
        //赋值出厂默认参数
        write_defalut_parm();
        config_file_fd = open(config_file_path, O_CREAT | O_RDWR | O_APPEND);
        if(config_file_fd == -1)
        {
            LOG_D("Establish config file failed!");
        }
        else
        {
            write_parm_to_config(config_file_fd);
            LOG_D("Write default config parameter successed.");
        }
    }
    else
    {
        config_file_fd = open(config_file_path, O_RDWR);
        read_config_to_parm(config_file_fd);
        LOG_D("Config file detected, finished reading parameters.");
    }
}
